﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class active_love2013_killYou : System.Web.UI.Page
{
    public int num1 = 0;
    public int num2 = 0;
    public int num3 = 0;
    public int num4 = 0;
    public int num5 = 0;
    public int num6 = 0;
    public int num7 = 0;
    protected void Page_Load(object sender, EventArgs e)
    {

        int useridx = MediaUtil.ReturnMemberId();
        string userid = MediaUtil.ReturnUserID();

        useridx = 21964264;
        userid = "flowx";

        if (useridx <= 0)
        {
            Response.Redirect("http://my.9158.com/login_pass.aspx?go=http://cugame.9158.com/active/pro/killyou.aspx");
            Response.End();
        }
        if (userid != "flowx" && userid != "vip1test")
        {
            Response.End();
        }  
        
        if (!Page.IsPostBack)
        {
            selectPro();
            selectActive();
            BindGoFishing();
        }
       
    }


    void selectActive()
    {
        GridView2.DataSource = Active();
        GridView2.DataBind();
    }
    void selectPro()
    {
        int ret = 0;
        GridView1.DataSource = pro(1, 0, 0, out ret);
        GridView1.DataBind();
    }

    public void BindGoFishing()
    {
        DataSet ds = getflowerkingData();
        if (ds.Tables.Count >0)
        {
            DataTable dt1 = new DataTable();
            dt1 = ds.Tables[0];
            if (dt1.Rows.Count > 0)
            {
              //  num1 = Convert.ToInt32(dt1.Rows[0][0]) * 40; //道具消耗
                num2 = Convert.ToInt32(dt1.Rows[0][1]) ;//参加人数
             
            }
            DataTable dt2 = new DataTable();
            dt2 = ds.Tables[1];
            if (dt2.Rows.Count > 0)
            {

                for (int i = 0; i < dt2.Rows.Count; i++)
                {
                    int reward = Convert.ToInt32(dt2.Rows[i][0]);
                    int num = Convert.ToInt32(dt2.Rows[i][1]);
                    if (reward == 8 || reward==11 || reward==20)
                    {
                        num1 = num1 + num * 500;
                    }
                    else if (reward == 13 || reward==16)
                    {
                        num1 = num1 + num * 5000;
                    }
                    else if (reward == 15 || reward == 18)
                    {
                        num1 = num1 + num * 100000;
                    }
                }
            }
            
           
        }


    }
    /// <summary>
    /// 查询概率
    /// </summary>
    /// <param name="useridx"></param>
    /// <returns></returns>
    static DataTable pro(int type, int id, int pro,out int ret)
    {
        DataTable dt = new DataTable();
        ret = 0;
        SqlParameter[] p =
                    {
                         SqlHelper.MakeInParam("@type",SqlDbType.Int,4,type),
                         SqlHelper.MakeInParam("@id",SqlDbType.Int,4,id),
                         SqlHelper.MakeInParam("@pro",SqlDbType.Int,4,pro),
                         SqlHelper.MakeOutParam("@ret",SqlDbType.Int,4)
                    };
        try
        {
            dt = SqlHelper.ExecuteDataTable(active.Conn, CommandType.StoredProcedure, "[UpdateActivePro]", p);
            ret = int.Parse(p[3].Value.ToString());
        }
        catch
        {

        }
        return dt;
    }



    /// <summary>
    /// 查询盈利
    /// </summary>
    /// <param name="useridx"></param>
    /// <returns></returns>
    static DataTable Active()
    {
        DataTable dt = new DataTable();
        SqlParameter[] p =
                    {

                    };
        try
        {
            dt = SqlHelper.ExecuteDataTable(active.Conn, CommandType.StoredProcedure, "[selectActive]", p);
        }
        catch
        {

        }
        return dt;
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text.Length ==0 || TextBox1.Text.Length==0)
            return;
        int id = 0;
        int Mypro = 0;
        int ret=0;
        int.TryParse(TextBox1.Text.Trim(), out id);
        int.TryParse(TextBox2.Text.Trim(), out Mypro);
        if (id == 0 || Mypro == 0)
            return;
        pro(2, id, Mypro, out ret);
        selectPro();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        selectActive();
    }


    public DataSet getgofishingData()
    {
        DataSet ds = new DataSet();
        SqlParameter[] p =
                    {
                         SqlHelper.MakeInParam("@stardate",SqlDbType.DateTime,20,"2013-04-29"),
                         SqlHelper.MakeInParam("@enddate",SqlDbType.DateTime,20,"2013-05-02 23:59:59")
                    };
        try
        {
            ds = SqlHelper.ExecuteDataset(active.Conn, CommandType.StoredProcedure, "[pr_active_gofishing]", p);
        }
        catch
        {
            ds = new DataSet();
        }

        return ds;
    }
    public DataSet getflowerkingData()
    {
        DataSet ds = new DataSet();
        SqlParameter[] p =
                    {
                         SqlHelper.MakeInParam("@stardate",SqlDbType.DateTime,20,"2013-05-10"),
                         SqlHelper.MakeInParam("@enddate",SqlDbType.DateTime,20,"2013-05-12 23:59:59")
                    };
        try
        {
            ds = SqlHelper.ExecuteDataset(active.Conn, CommandType.StoredProcedure, "[AS_Select_flowekingResult]", p);
        }
        catch
        {
            ds = new DataSet();
        }

        return ds;
    }

    protected void Button3_Click(object sender, EventArgs e)
    {
        BindGoFishing();
    }
}
